<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="../include/base.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<link rel='stylesheet' type='text/css' href='${basePath }/fullcalendar-1.5.3/fullcalendar/fullcalendar.css' />
<link rel='stylesheet' type='text/css' href='${basePath }/fullcalendar-1.5.3/fullcalendar/fullcalendar.print.css' media='print' />
<script type='text/javascript' src='${basePath }/fullcalendar-1.5.3/jquery/jquery-1.7.1.min.js'></script>
<script type='text/javascript' src='${basePath }/fullcalendar-1.5.3/jquery/jquery-ui-1.8.17.custom.min.js'></script>
<script type='text/javascript' src='${basePath }/fullcalendar-1.5.3/fullcalendar/fullcalendar.min.js'></script>
<script type='text/javascript'>

	$(document).ready(function() {
	
		var date = new Date();
		var d = date.getDate();
		var m = date.getMonth();
		var y = date.getFullYear();
		
		var calendar = $('#calendar').fullCalendar({
			header: {
				left: 'prev,next today',
				center: 'title',
				right: 'month,agendaWeek,agendaDay'
			},
			selectable: true,
			selectHelper: true,
			select: function(start, end) {
				var title = prompt('Event Title:');
				if (title) {
					$.post("${basePath}/task/addtask",{"task.title":title,"task.start":start.getTime(),"task.end":end.getTime()},function(obj){
						calendar.fullCalendar('renderEvent',
							{
								id: obj.id,
								title: obj.title,
								start: obj.start,
								end: obj.end
								
							},
							true // make the event "stick"
						);
					});
				}
				calendar.fullCalendar('unselect');
			},
			editable: true,
			events: "${basePath}/task/taskjson",
			disableDragging: false,
			
			eventDrop: function(event,dayDelta,minuteDelta,revertFunc) {

				$.post("${basePath}/task/edittask",{"task.id":event.id,"task.title":event.title,"task.start":event.start.getTime(),"task.end":event.end.getTime()});

		    },
			eventResize:function(event,dayDelta,minuteDelta,revertFunc) {

				$.post("${basePath}/task/edittask",{"task.id":event.id,"task.title":event.title,"task.start":event.start.getTime(),"task.end":event.end.getTime()});

		    },
			
		    eventClick: function(event, jsEvent, view) {
		    	//alert(event.end + " : " + event.start);
		    	var title = prompt('Event Title:',event.title);
				if (title) {
					$.post("${basePath}/task/edittask",{"task.id":event.id,"task.title":event.title,"task.start":event.start.getTime(),"task.end":event.end.getTime()});
					
					event.title = title;
					$('#calendar').fullCalendar('updateEvent', event);
				}
				calendar.fullCalendar('unselect');
		    }
		});
		
	});

</script>
<style type='text/css'>

	body {
		margin-top: 40px;
		text-align: center;
		font-size: 14px;
		font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
		}

	#calendar {
		width: 900px;
		margin: 0 auto;
		}

</style>
</head>
<body>
<div id='calendar'></div>
</body>
</html>
